Ext.onReady(function() {

    Ext.QuickTips.init();
    // 元数据的store
    var store2 = new Ext.data.Store({
        storeId: 'store2',
        proxy: new Ext.data.HttpProxy({
            url: 'metadata.action?code=property'
        }),
        reader: new Ext.data.JsonReader({
            fields: [{
                    name: 'name'
                }, {
                    name: 'value'
                }]
        })
    });


    //获取车辆列表
    var carList_store = new Ext.data.Store({
        storeId: 'store3',
        proxy: new Ext.data.HttpProxy({
            url: 'Get_Car_List.action'
        }),
        reader: new Ext.data.JsonReader({
            fields: [
                {
                    name: 'name'
                }, {
                    name: 'value'
                }
            ]
        })
    });

    //获取驾驶员列表
    var driverList_store = new Ext.data.Store({
        storeId: 'store4',
        proxy: new Ext.data.HttpProxy({
            url: 'Get_Data_List.action?method=driver'
        }),
        reader: new Ext.data.JsonReader({
            fields: [
                {
                    name: 'name'
                }, {
                    name: 'value'
                }
            ]
        })
    });




    var peccancy = new Ext.FormPanel({
        labelAlign: 'peccancy',
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 600,
        items: [{
                layout: 'column',
                items: [{
                        columnWidth: .5,
                        layout: 'form',
                        items: [{
                                xtype: 'hidden',
                                name: 'id'
                            }, new Ext.form.ComboBox({
                                fieldLabel: '车牌号码',
                                name: 'car_code',
                                displayField: 'name',
                                valueField: 'name',
                                emptyText: '车牌号码',
                                anchor: '95%',
                                typeAhead: true,
                                triggerAction: 'all',
                                queryParam: 'name', autoSelect: false,  triggerAction : 'all', store: carList_store
                            }), new Ext.form.ComboBox({
                                fieldLabel: '驾驶员',
                                name: 'driver',
                                displayField: 'name',
                                valueField: 'name',
                                emptyText: '驾驶员',
                                anchor: '95%',
                                typeAhead: true,
                                triggerAction: 'all',
                                queryParam: 'name',
                                minChars: 2,
                                store: driverList_store
                            }), {
                                xtype: 'datefield',
                                fieldLabel: '违章时间',
                                emptyText: '违章时间（必填）',
                                allowBlank: false,
                                name: 'time',
                                altFormats: 'Ymd',
                                format: 'Y-m-d',
                                dateFormat: 'Ymd',
                                anchor: '95%'
                            }, {
                                xtype: 'textfield',
                                fieldLabel: '违章事项',
                                emptyText: '违章事项（必填）',
                                allowBlank: false,
                                name: 'detail',
                                anchor: '95%'
                            }]
                    }, {
                        columnWidth: .5,
                        layout: 'form',
                        items: [{
                                xtype: 'textfield',
                                fieldLabel: '违章地点',
                                emptyText: '违章地点',
                                name: 'area',
                                anchor: '95%'
                            }, {
                                xtype: 'textfield',
                                fieldLabel: '处理结果',
                                emptyText: '处理结果',
                                name: 'process',
                                anchor: '95%'
                            }]
                    }]
            }, {
                xtype: 'htmleditor',
                id: 'remark',
                name: 'remark',
                fieldLabel: '备注',
                //height:200,
                anchor: '98%'
            }]
    });

    var win = new Ext.Window({
        id: 'win',
        title: "添加车辆违章记录",
        border: false,
        bodyBorder: false,
        // layout:'fit',
        width: 600,
        closeAction: 'hide',
        modal: true,
        tbar: ['-', {
                text: ' 提交并继续',
                handler: function() {
                    onSubmit();
                }
            }, '-', {
                text: '重置',
                handler: function() {
                    peccancy.getForm().reset();
                }
            }, '-'],
        items: [peccancy]
    }).show();

    function onSubmit() {
        // 提交表单
        if (peccancy.getForm().isValid()) {
            var submitValues = peccancy.getForm().getValues();
            for (var param in submitValues) {
                if (peccancy.form.findField(param)
                        && peccancy.form.findField(param).emptyText == submitValues[param]) {
                    peccancy.form.findField(param).setValue(' ');
                }
            }
            peccancy.getForm().submit({
                url: 'PeccancyAction.action',
                waitMsg: '数据保存中...',
                submitEmptyText: false,
                success: function(c, d) {
                    Ext.MessageBox.alert("操作信息", "成功信息保存！");
                    peccancy.getForm().reset();
                },
                failure: function(c, d) {
                    Ext.MessageBox.show({
                        title: "操作信息",
                        msg: "信息保存出错，请联系管理员！",
                        buttons: Ext.MessageBox.OK,
                        icon: "ext-mb-error"
                    });
                }
            });
        }
    }



});
